package com.qf.controller;

import com.qf.pojo.Recipe;
import com.qf.service.RecipeService;
import com.qf.utils.Msg;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("/recipe")
public class RecipeController {
    @Autowired
    private RecipeService recipeService;

    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    @ResponseBody
    public String insert(@RequestBody Msg<Recipe> recipeUtils){
        for(Recipe recipe:recipeUtils.getList()){
            int insert = recipeService.insert(recipe);
            if(insert==0){
                return "error";
            }
        }
        return "success";
    }

    @RequestMapping("/selectAll")
    @ResponseBody
    public List<Recipe> selectAll(){
        Recipe recipe=new Recipe();
        List<Recipe> select = recipeService.select(recipe);
        return select;
    }
}
